package com.xoa.service.party;

import com.xoa.dao.party.PartyMeetingRecordsMapper;
import com.xoa.model.party.PartyMeetingRecords;
import com.xoa.model.party.PartyMeetingRecordsWithBLOBs;
import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class PartyMeetingRecordsService {
    @Autowired
    private PartyMeetingRecordsMapper partyMeetingRecordsMapper;

    //查询党会记录列表
    public ToJson findAll(PartyMeetingRecordsWithBLOBs partyMeetingRecordsWithBLOBs, Integer page, Integer pageSize, boolean userFlag){
        ToJson toJson=new ToJson();
        Map<String,Object> pamap=new HashMap<String,Object>();
        pamap.put("entity",partyMeetingRecordsWithBLOBs);
        PageParams pageParams=new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        pageParams.setUseFlag(true);
        pamap.put("pageParams",pageParams);
        toJson.setFlag(0);
        toJson.setMsg("查询成功");
        toJson.setObj(partyMeetingRecordsMapper.queryAll(pamap));
        toJson.setTotleNum(pageParams.getTotal());
        return toJson;
    }

    //新增党会记录
    public ToJson add(PartyMeetingRecordsWithBLOBs partyMeetingRecordsWithBLOBs) {
        ToJson json = new ToJson();
        int a = 0;
        try {
            a = partyMeetingRecordsMapper.insert(partyMeetingRecordsWithBLOBs);
            if (a > 0) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg("err");
            e.printStackTrace();
        } finally {
            return json;
        }
    }

        //删除党会记录
        public ToJson delete(Integer meetingId){
            ToJson json=new ToJson();
            int a= 0;
            try {
                a = partyMeetingRecordsMapper.deleteByPrimaryKey(meetingId);
                if(a>0){
                    json.setMsg("ok");
                    json.setFlag(0);
                }
            } catch (Exception e) {
                json.setFlag(1);
                json.setMsg("err");
                e.printStackTrace();
            } finally {
                return json;
            }
        }

        //根据id查询党会记录
    public PartyMeetingRecords findOne(Integer meetingId){
        return partyMeetingRecordsMapper.selectByPrimaryKey(meetingId);
}

        //修改党会记录
    public ToJson update(PartyMeetingRecordsWithBLOBs partyMeetingRecordsWithBLOBs){
        ToJson json=new ToJson();
        int a= 0;
        try {
            a = partyMeetingRecordsMapper.updateByPrimaryKeyWithBLOBs(partyMeetingRecordsWithBLOBs);
            if(a>0){
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg("err");
            e.printStackTrace();
        } finally {
            return json;
        }
    }



}
